package fragments;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.wangjin.menu.R;

import model.ArrangementItem;

import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;

/**
 * Created by wangjin on 15/6/18.
 */
public class ArrangmentFragment extends ListFragment {

    ArrangementItem[] arrangementItems;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        arrangementItems = new ArrangementItem[2];
        arrangementItems[0] = new ArrangementItem();
        arrangementItems[0].setTime("8:00 ~ 9:00");
        arrangementItems[0].getArrangements().add("草图设计");
        arrangementItems[0].getArrangements().add("原型设计");
        arrangementItems[1] = new ArrangementItem();
        arrangementItems[1].setTime("15:00 ~ 17:00");
        arrangementItems[1].getArrangements().add("期末答辩商讨");
        arrangementItems[1].getArrangements().add("原型设计");

        Adpater adpater = new Adpater();
        setListAdapter(adpater);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.arrangment_fragment_layout,container,false);
        return v;
    }

    class Adpater extends ArrayAdapter<ArrangementItem>{

        public Adpater(){
            super(getActivity(),0,arrangementItems);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if(convertView == null){
                convertView = getActivity().getLayoutInflater().inflate(R.layout.arrangement_item_layout,null);
                TextView t = (TextView) convertView.findViewById(R.id.textView21);
                t.setText(arrangementItems[position].getArrangements().get(0));
                t = (TextView) convertView.findViewById(R.id.textView22);
                t.setText(arrangementItems[position].getArrangements().get(1));
                t = (TextView) convertView.findViewById(R.id.t1);
                t.setText(arrangementItems[position].getTime());
                return convertView;
            }else {
                return convertView;
            }
        }
    }


}
